<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('教师课表信息')" />
    <th:block th:include="include :: select2-css" />
    <th:block th:include="include :: bootstrap-select-css" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>排课名称：</label>
                                <select id ="mainId" name="mainId" th:with="type=${@course.getRuleList()}" class="form-control">
                                    <option th:each="r : ${type}" th:text="${r.name}" th:value="${r.id}"></option>
                                </select>
                            </li>
                            <li>
                                <label>教师：</label>
                                <select name="teacherId" id="teacherId" class="form-control">
                                    <option th:each="c : ${pList}" th:text="${c.userName}" th:value="${c.userId}"></option>
                                </select>
                            </li>

                            <li>
                                <label>从第：</label>
                                <input type="number" name="params[bType]" id="beginW" th:value="1"  min="1"/>
                                <label >周~第</label>
                                <input type="number" name="params[eType]" id="endW" th:value="2" min="1"/>周
                            </li>
                            <li class="hidden">
                                <input type="text" name="params[printType]" th:value="T"/>
                            </li>

                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="query()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                                <a class="btn btn-info btn-rounded btn-sm" onclick="printAll()"><i class="fa fa-print"></i>&nbsp;打印设定周期</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="col-sm-12 select-table table-striped table-bordered">
                <div class="row">
                    <span class='badge badge-danger' disabled='true'>代表请假</span>
                    <span class='badge badge-success' disabled='true'>代表替课</span>
                    <span class='badge' style="background-color: #ffffff" disabled='true'>正常</span>
                </div>
                <table id="bootstrap-table"></table>
            </div>

        </div>
    </div>
    <th:block th:include="include :: footer" />
     <th:block th:include="include :: select2-js" />
     <th:block th:include="include :: bootstrap-select-js" />
    <script th:inline="javascript">
        var prefix = ctx + "school/courseConfig";
        var options = {
            detailView: true,
            onExpandRow : function(index, row, $detail) {

                initChildTable(index, row, $detail);
            },
            columns: [
                {
                    field: 'kid',
                    title: 'kid',
                    visible:false
                },
                {
                    field: 'name',
                    title: '排课名称',
                },
                {
                    field: 'scheduleName',
                    title: '名称',
                },
                {
                    field: 'typeName',
                    title: '教师名称',
                    width:80
                },
                {
                    field: 'mId',
                    title: 'MainId',
                    visible:false
                },
                {
                    field: 'typeId',
                    title: '教师Id',
                    visible:false
                },
                {
                    field: 'type',
                    title: '周',
                    visible:false
                } ,
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs" onclick="printSchedule('+index+')"><i class="fa fa-print"></i>打印</a> ');
                        return actions.join('');
                    }
                }
            ],
            data:[]
        }
        var options2 = {
            columns: [
                {
                    field: 'section',
                    title: '节次',
                    width:60
                },
                {
                    field: 'w1',
                    title: '星期一',
                    width:80,
                    formatter:function(value, row, index) {
                        return fmtV(row,value,"w1");
                    }
                },
                {
                    field: 'w2',
                    title: '星期二',
                    width:80,
                    formatter:function(value, row, index) {
                        return fmtV(row,value,"w2");
                    }
                },
                {
                    field: 'w3',
                    title: '星期三',
                    width:80,
                    formatter:function(value, row, index) {
                        return fmtV(row,value,"w3");
                    }
                },
                {
                    field: 'w4',
                    title: '星期四',
                    width:80,
                    formatter:function(value, row, index) {
                        return fmtV(row,value,"w4");
                    }
                },
                {
                    field: 'w5',
                    title: '星期五',
                    width:80,
                    formatter:function(value, row, index) {
                        return fmtV(row,value,"w5");
                    }
                },
                {
                    field: 'w6',
                    title: '星期六',
                    width:80,
                    formatter:function(value, row, index) {
                        return fmtV(row,value,"w6");
                    }
                },
                {
                    field: 'w7',
                    title: '星期日',
                    width:80,
                    formatter:function(value, row, index) {
                        return fmtV(row,value,"w7");
                    }
                }
            ],
            data:[]
        }
        $(function () {
            $("#bootstrap-table").bootstrapTable(options);
            query();
        });

        initChildTable = function(index, row, $detail) {
            var childTable = $detail.html('<table style="table-layout:fixed"></table>').find('table');
            $(childTable).bootstrapTable(options2);
            $(childTable).bootstrapTable('load',row.list);
        }

        function printSchedule(index) {
            var  tableData = $("#bootstrap-table").bootstrapTable('getData',true);
            var row = tableData[index];
            console.log(row);
            window.open(prefix+"/pdfRowTeacher/"+row.kid+"/"+row.weeks);
        }
        
        function printAll() {
            var mId = $('#mainId').val();
            // console.log(mId);
            var tId = $("#teacherId").val();
            // console.log(tId);
            var bw = $("#beginW").val();
            var ew = $("#endW").val();
            let key = tId+"_"+bw+"_"+ew;
            window.open(prefix+"/pdfAll/"+mId+"/"+key+""+"/1");
        }

        function fmtV(row,value,key){
            var st = row[key+"_s"];
            if(st != undefined){
                if(st==-1){
                    return "<span class='badge badge-danger' disabled='true'>"+value+"</span>"
                }
                if(st ==1){
                    return "<span class='badge badge-success'>"+value+"</span>"
                }
            }
            return value;
        }

        function query() {
            $.modal.loading("执行查询...");
            var data = $('#formId').serializeJSON();
            $.ajax({
                type: "post",
                url:prefix+'/getClazzCourseInfoTeacher',
                async:false,
                dataType: "json",
                data:data,
                success:function (res) {
                    $.modal.closeLoading();
                    if(res&&res.length>0){
                        $("#bootstrap-table").bootstrapTable("load",res);
                    }
                }
            });
        }
    </script>
</body>
</html>